package io.renren.modules.yckj.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.yckj.dao.TeamRelationDao;
import io.renren.modules.yckj.dto.TeamRelationDTO;
import io.renren.modules.yckj.entity.TeamRelationEntity;
import io.renren.modules.yckj.service.TeamRelationService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 检测关系表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2025-04-17
 */
@Service
public class TeamRelationServiceImpl extends CrudServiceImpl<TeamRelationDao, TeamRelationEntity, TeamRelationDTO> implements TeamRelationService {

    @Override
    public QueryWrapper<TeamRelationEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");
        Object teamId = params.get("teamId");
        Object userId = params.get("userId");
        Object status = params.get("status");
        String username = (String) params.get("username");

        QueryWrapper<TeamRelationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);
        wrapper.like(StrUtil.isNotBlank(username), "username", username);
        wrapper.eq(ObjectUtil.isAllNotEmpty(teamId), "team_id", teamId);
        wrapper.eq(ObjectUtil.isAllNotEmpty(userId), "user_id", userId);
        wrapper.eq(ObjectUtil.isAllNotEmpty(status), "status", status);
        return wrapper;
    }


    @Override
    public TeamRelationEntity getByTeamIdAndUserId(Long teamId, Long userId) {
        return baseDao.getByTeamIdAndUserId(teamId, userId);
    }

    @Override
    public List<TeamRelationDTO> getApplyList(Long userId) {
        List<TeamRelationEntity> entityList = baseDao.getApplyList(userId);
        return ConvertUtils.sourceToTarget(entityList, TeamRelationDTO.class);
    }

    @Override
    public List<TeamRelationDTO> getRelationList(Map<String, Object> params) {
        List<TeamRelationEntity> entityList = baseDao.getRelationList(params);
        return ConvertUtils.sourceToTarget(entityList, TeamRelationDTO.class);
    }


}